﻿using CMS.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Models
{
    //流水记录
    public class RecordProvider : IProvider<Record>
    {
        private CargorDBModel1 db = new CargorDBModel1();
        public int Delete(Record t)
        {
           if(t==null) return 0;
           var model=db.Record.ToList().FirstOrDefault(item=>item.Id==t.Id);
            if (model!=null)
            {
                db.Record.Remove(model);
                return db.SaveChanges();
            }
            return 0;
        }

        public int Insert(Record t)
        {
           if(t==null)return 0;
           db.Record.Add(t);
            return db.SaveChanges();
        }

        public List<Record> Select()
        {
           return db.Record.ToList();
        }

        public int Update(Record t)
        {
          if(t==null) return 0; 
          var model=db.Record.ToList().FirstOrDefault(item=>item.Id==t.Id);
            if (model == null)
            {
                model.Number=t.Number;
                return db.SaveChanges();
            }
            return 0;
        }
    }
}
